﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ScheduleMaker.DB.Domain.Core;
using ScheduleMaker.ConfigManager;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.CoreDAO;
using ScheduleMaker.DB;

namespace ScheduleMaker
{
    public partial class smAdmSubjectAddForm : Form
    {
        smAdminForm parentForm;

        public smAdmSubjectAddForm( smAdminForm _parentForm)
        {
            InitializeComponent();
            this.parentForm = _parentForm;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //// dodawanie nowego przedmiotu

            if (regexpHelper.Instance.isClassroomNameCorrect(tbSubjectName.Text))
            {

                SubjectDAO subjectDAO = DAOFactory.getSubjectDAO(ConfigManager.ConfigManager.getConfiguration().Type);


                if (ConfigManager.ConfigManager.getConfiguration().Type == Mode.School)
                {
                    DB.Domain.Core.Subject subject = new SubjectSchool();
                    subject.Name = tbSubjectName.Text;
                    subjectDAO.save(subject);
                }
                else
                {
                    DB.Domain.Core.Subject subject = new SubjectUniversity();
                    subject.Name = tbSubjectName.Text;
                    subjectDAO.save(subject);
                }

                MessageBox.Show("Przedmiot zsotał dodany", "Dodanie przedmiotu", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.parentForm.getSubjectList();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Niepoprawna nazwa przedmiotu!", "Dodanie przedmiotu", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
